package com.visikard.ui.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;

import com.visikard.application.Constant;
import com.visikard.ui.R;
import com.visikard.ui.fragment.CreateCouponFragment;
import com.visikard.utility.Utils;

public class CouponBuilderActivityV3 extends BaseFragmentActivity {

	private CreateCouponFragment mCreateCouponFragment;

	public CreateCouponFragment getCreateCouponFragment() {
		mCreateCouponFragment = (CreateCouponFragment) getSupportFragmentManager().findFragmentByTag(
				Constant.CREATE_COUPON_FRAGMENT_TAG);
		if (mCreateCouponFragment == null) {
			mCreateCouponFragment = new CreateCouponFragment();
		}
		return mCreateCouponFragment;
	}

	private void initCreateCouponFragment() {

		// add a fragment
		mCreateCouponFragment = getCreateCouponFragment();

		Utils.toFragmentWithoutBackstack(CouponBuilderActivityV3.this, mCreateCouponFragment,
				Constant.CREATE_COUPON_FRAGMENT_TAG, R.id.framelayout_coupon_builder);
	}

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		setContentView(R.layout.coupon_builder_activity);
		initCreateCouponFragment();
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		String tag = Utils.getCurrentFragmentTag(this, R.id.framelayout_coupon_builder);

		if (tag != null) {

			if (tag.equals(Constant.CREATE_COUPON_FRAGMENT_TAG)) {
				finish();
			}
			else {
				FragmentManager fm = this.getSupportFragmentManager();
				fm.popBackStack();
			}

		}

	}
}
